import { getBranchList } from '@/services/api';
import type { ActionType } from '@ant-design/pro-components';
import { ProTable } from '@ant-design/pro-components';
import { isEqual } from 'lodash';
import React, { useRef } from 'react';

/* 分店信息 */
const BranchInformation: React.FC<unknown> = () => {
  const actionRef = useRef<ActionType>();

  const columns: any = [
    {
      title: 'oid',
      key: 'oid',
      dataIndex: 'oid',
      hideInSearch: true,
    },
    {
      title: '分店名稱',
      dataIndex: 'name',
      hideInSearch: true,
      key: 'name',
    },
    {
      title: '分店最低消費',
      dataIndex: 'minSale',
      hideInSearch: true,
      key: 'minSale',
    },
  ];

  return (
    <ProTable
      columns={columns}
      actionRef={actionRef}
      bordered
      request={async () => {
        const { Items = [] } = await getBranchList();

        return {
          data: Items || [],
          success: true,
          total: Items?.length ?? 0,
        };
      }}
      cardProps={{
        bodyStyle: {
          padding: 0,
        },
      }}
      rowKey="id"
      search={false}
      pagination={{
        defaultPageSize: 50,
      }}
      dateFormatter="string"
    />
  );
};

export default React.memo(BranchInformation, (prev, next) =>
  isEqual(prev, next),
);
